package com.ccn.crm.util;

import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GetCustomerInfo {
    public static Map<String, Object> GetCustomerInfo(String objectDataId , Map<String, Object> token) {
        String url = "https://open.fxiaoke.com/cgi/crm/v2/data/get";
        Map<String, Object> jsonObject = new HashMap<String, Object>();
        //设置访问参数
        String corpAccessToken = (String)token.get("corpAccessToken");
        String corpId = (String)token.get("corpId");
        String currentOpenUserId = (String)token.get("currentOpenUserId");

        jsonObject.put("corpAccessToken",corpAccessToken);
        jsonObject.put("corpId",corpId);
        jsonObject.put("currentOpenUserId",currentOpenUserId);

        Map<Object,Object> data=new HashMap<Object,Object>();
        data.put("objectDataId",objectDataId);
        data.put("dataObjectApiName","AccountObj");
        jsonObject.put("data",data);
        //把参数转化为字符串
        String json = JSON.toJSONString(jsonObject);
        //调用工具进行跨域请求获取token的corpID等参数
            String post = HttpUtil.httpProxy(url, json, "post", "application/json");
        //  String str="{\"corpAccessToken\":\"7129AE8DA6F9C5188C40BA920118A0E2\",\"corpId\":\"FSCID_A6D390D2E5FFF878491C1F5E6DA2994B\",\"expiresIn\":2422,\"errorCode\":0,\"errorMessage\":\"success\"}\n";
        //将获取的参数转化成map类型
        HashMap customerInfo = JSON.parseObject(post, HashMap.class);
        return customerInfo;
    }
}
